//
//  CENetWorkManager.h
//  WiFiKeyWidget_speed
//
//  Created by lzy on 2018/11/28.
//  Copyright © 2018年 lzy. All rights reserved.
//

/*Http网络库，基于‘AFNetworking’再次封装，主要有get、post、download、upload，网络监控等基本功能，
 *⚠️导入‘AFNetworking’库，推荐使用cocoaPods导入（pod 'AFNetworking'）⚠️
 *⚠️Build Setting—>Other Linker Flags 选项添加：-all_load 或者 -ObjC⚠️
 */

#import <Foundation/Foundation.h>
@class AFNetworking;
@class AFHTTPSessionManager;

//
typedef NS_ENUM(NSInteger,NetWorkConnectState) {
    NetWorkConnect_NotReachable = 0,        //无网络
    NetWorkConnect_WIFI = 1,                //wifi
    NetWorkConnect_WWAN = 2,                //gprs
    NetWorkConnect_UNKNOW = 3,              //未知
};

typedef void (^ObserveComplete)(NetWorkConnectState state);

@interface CENetWorkManager : NSObject

@property (nonatomic,assign) NetWorkConnectState netWorkConnectStatus;

+(CENetWorkManager *_Nullable)shared;

-(void)startObserveConnectionAvailable:(ObserveComplete _Nullable)complete target:(id)target;

#pragma mark -停止观察网络连接状况
-(void)stopObserveConnectionAvailable;

#pragma mark -停止观察网络连接状况
-(void)removeTarget:(id)target;

#pragma mark - Default AFHTTPSessionManager
+(AFHTTPSessionManager * _Nullable)getDefaultHttpManagerWithJSON:(BOOL)JSON
                                               timeOut:(NSInteger)timeOut
                                             headerDic:(NSDictionary * _Nullable)headerDic
                                               cerData:(NSData *_Nullable)cerData;

#pragma mark - get请求 (sign 是否需要签名)
+(NSURLSessionTask *_Nullable)getNetWorkingWithURl:(NSString*_Nullable)urlStr
                                            praDic:(NSDictionary *_Nullable)praDic
                                         headerDic:(NSDictionary *_Nullable)headerDic
                                              sign:(BOOL)sign
                                           success:(void(^_Nullable)(NSDictionary * _Nonnull dataDic))success
                                              fail:(void(^_Nullable)(NSString * _Nonnull failStr,BOOL isCanceled))fail;

+(NSURLSessionTask *_Nullable)getNetWorkingWithURl:(NSString *_Nullable)urlStr
                                   praDic:(NSDictionary *_Nullable)praDic
                               JSONFormat:(BOOL)JSONFormat
                                  timeOut:(NSInteger)timeOut
                                headerDic:(NSDictionary *_Nullable)headerDic
                                     time:(NSTimeInterval)time
                                     sign:(BOOL)sign
                                  success:(void(^_Nullable)(NSDictionary * _Nullable dataDic))success
                                     fail:(void(^_Nullable)(NSString * _Nullable failStr,BOOL isCanceled))fail
                                 progress:(void(^_Nullable)(long long progress))progress;

#pragma mark - post请求 (sign 是否需要签名)
+(NSURLSessionTask *_Nullable)postNetWorkingWithURl:(NSString*_Nullable)urlStr
                                    praDic:(NSDictionary *_Nullable)praDic
                                 headerDic:(NSDictionary *_Nullable)headerDic
                                      sign:(BOOL)sign
                                   success:(void(^_Nullable)(NSDictionary * _Nullable dataDic))success
                                      fail:(void(^_Nullable)(NSString * _Nullable failStr,BOOL isCanceled))fail;

+(NSURLSessionTask *_Nullable)postNetWorkingWithURl:(NSString * _Nullable)urlStr
                                    praDic:(NSDictionary *_Nullable)praDic
                                JSONFormat:(BOOL)JSONFormat
                                   timeOut:(NSInteger)timeOut
                                 headerDic:(NSDictionary *_Nullable)headerDic
                                      time:(NSTimeInterval)time
                                      sign:(BOOL)sign
                                   success:(void(^_Nullable)(NSDictionary * _Nullable dataDic))success
                                      fail:(void(^_Nullable)(NSString * _Nullable failStr,BOOL isCanceled))fail
                                  progress:(void(^_Nullable)(long long progress))progress;

+(NSURLSessionTask *_Nullable)postNetWorkingWithURl:(NSString*_Nullable)urlStr
                                    praDic:(NSDictionary *_Nullable)praDic
                                JSONFormat:(BOOL)JSONFormat
                                   timeOut:(NSInteger)timeOut
                                 headerDic:(NSDictionary *_Nullable)headerDic
                                      time:(NSTimeInterval)time
                                     files:(NSArray *_Nullable)files
                                 fileNames:(NSArray *_Nullable)fileNames
                                      sign:(BOOL)sign
                                   success:(void(^_Nullable)(NSDictionary * _Nullable dataDic))success
                                      fail:(void(^_Nullable)(NSString * _Nullable failStr,BOOL isCanceled))fail
                                  progress:(void(^_Nullable)(long long progress))progress;

#pragma mark - head
+(NSURLSessionTask *_Nullable)headNetWorkingWithURl:(NSString *_Nullable)urlStr
                                             praDic:(NSDictionary *_Nullable)praDic
                                          headerDic:(NSDictionary *_Nullable)headerDic
                                               sign:(BOOL)sign
                                            success:(void(^_Nullable)(NSURLSessionDataTask * _Nullable task))success
                                               fail:(void(^_Nullable)(NSString * _Nullable failStr,BOOL isCanceled))fail;

+(NSURLSessionTask *_Nullable)headNetWorkingWithURl:(NSString * _Nullable)urlStr
                                             praDic:(NSDictionary * _Nullable)praDic
                                         JSONFormat:(BOOL)JSONFormat
                                            timeOut:(NSInteger)timeOut
                                          headerDic:(NSDictionary * _Nullable)headerDic
                                               time:(NSTimeInterval)time
                                               sign:(BOOL)sign
                                            success:(void(^_Nullable)(NSURLSessionDataTask * _Nullable task))success
                                               fail:(void(^_Nullable)(NSString * _Nullable failStr,BOOL isCanceled))fail;

+(NSURLSessionTask *_Nullable)downloadTaskWithURl:(NSString*_Nullable)urlStr
                                 timeOut:(NSInteger)timeOut
                            downLoadPath:(NSString *_Nullable)downLoadPath
                                 success:(void(^_Nullable)(NSURLResponse * _Nullable response,NSURL * _Nullable filePath))success
                                    fail:(void(^_Nullable)(NSString * _Nullable failStr,BOOL isCanceled))fail
                                progress:(void(^_Nullable)(float progress,NSProgress * _Nullable downloadProgress))progress;

+(NSURLSessionTask *_Nullable)uploadTaskWithURl:(NSString*_Nullable)urlStr
                            uploadData:(NSData *_Nullable)uploadData
                               timeOut:(NSInteger)timeOut
                               success:(void(^_Nullable)(NSURLResponse * _Nullable response, NSDictionary * _Nullable dataDic))success
                                  fail:(void(^_Nullable)(NSString * _Nullable failStr,BOOL isCanceled))fail
                              progress:(void(^_Nullable)(float progress,NSProgress * _Nullable uploadProgress))progress;

@end


